package org.hismig.utils;

import java.util.List;

import org.hismig.cfg.DataBase;
import org.hismig.cfg.Param;
import org.hismig.cfg.Table;

/**
 * @declare: //TODO <br />
 *           This class created by Vansion.Hopihit on 2012-07-04 <br />
 *           <a href="mailto:vansionhopihit@gmail.com">Contact Me</a>
 * @version 1.0
 * @author Vansion.Hopihit
 * 
 */
public class ListTool {

	public static String getParamByName(List<Param> params, String name) {
		CheckTool.checkNotEmpty(name);

		if (null != params) {
			for (Param param : params) {
				if (name.equalsIgnoreCase(param.getName())) {
					return param.getValue();
				}
			}
		}

		return null;
	}

	public static String getParamByName(List<Param> params, String name,
			String defaultValue) {

		String value = getParamByName(params, name);
		return null != value ? value : defaultValue;
	}

	public static DataBase getDataBaseByName(List<DataBase> databases,
			String dbName) {
		CheckTool.checkNotEmpty(dbName);

		if (null != databases) {
			for (DataBase db : databases) {
				if (dbName.equalsIgnoreCase(db.getName())) {
					return db;
				}
			}
		}

		return null;
	}

	public static Table getTableByName(List<Table> tables, String tableName) {
		CheckTool.checkNotEmpty(tableName);

		if (null != tables) {
			for (Table table : tables) {
				if (tableName.equalsIgnoreCase(table.getName())) {
					return table;
				}
			}
		}

		return null;
	}
}
